package com.solrtest.config;

import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.SystemDefaultHttpClient;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.springframework.context.annotation.Bean;
import org.springframework.data.solr.core.SolrTemplate;
import org.springframework.stereotype.Component;

@Component
public class SolrTemplateConfig {


    @Bean
    public HttpSolrClient solrClient() {
        //已经弃用的方法
//        HttpClient httpClient = new SystemDefaultHttpClient();
        HttpClient httpClient = HttpClientBuilder.create().build();
        return new HttpSolrClient.Builder("http://user:user123@192.168.1.8:8983/solr").withHttpClient(httpClient).build();
    }

    @Bean
    public SolrTemplate solrTemplate(SolrClient solrClient) {
        return new SolrTemplate(solrClient);
    }
}
